<?php if($this->Session->read('Auth.User.role') === 'admin'): ?>
<ul class="submenu">
<li <?php if($this->params['action'] == 'index'): echo 'class="active"'; endif; ?> ><?php echo $this->Html->link('Holidays',array('action' => 'index')); ?></li>
<li <?php if($this->params['action'] == 'add'): echo 'class="active"'; endif; ?> ><?php echo $this->Html->link('Add holiday',array('action' => 'add')); ?></li>
</ul>
<?php endif; ?>

<?php 
$userbyid = array();
foreach($users as $user): 
	$userbyid[$user['User']['id']] = $user['User'];
endforeach;
?>

<?php echo $this->Paginator->numbers(array('first' => 'First page')); ?>
<table>
    <tr>
        <th></th>
        <th>Holiday</th>
        <th>Start Date</th>
        <th>End Date</th>
        <th colspan="2">Action</th>
        <th>Modified</th>
        <th>Modified By</th>
        <th>Created</th>
        <th>Created By</th>
    </tr>

    <!-- Here is where we loop through our $posts array, printing out post info -->

    <?php foreach ($holidays as $key => $holiday): ?>
    <tr>
        <td><?php echo $key+1; ?></td>
        <td><?php echo $holiday['Holiday']['title']; ?></td>
        <td><?php echo date("F j, Y", strtotime($holiday['Holiday']['start_date'])); ?></td>
        <td><?php echo date("F j, Y", strtotime($holiday['Holiday']['end_date'])); ?></td>
        <td><?php
			if($this->Session->read('Auth.User.role') === 'admin'):
		 		echo $this->Form->postLink('Delete',
					array('action' => 'delete', $holiday['Holiday']['id']),
					array('confirm' => 'This holiday will be completely deleted from the system. Are you sure?'));
			endif;?></td>
        <td>
            <?php echo $this->Html->link('Edit',
				array('controller' => 'holidays', 'action' => 'edit', $holiday['Holiday']['id'])); ?>
        </td>
        <td><?php echo date("F j, Y, g:i a", strtotime($holiday['Holiday']['modified'])); ?></td>
        <td><?php 
		if(array_key_exists($holiday['Holiday']['modified_by'],$userbyid)):
			$name = explode('@',$userbyid[$holiday['Holiday']['created_by']]['username']);
			$name = explode('.',$name[0]);
			echo implode(' ',$name);
		endif;
		 ?></td>
        <td><?php echo date("F j, Y, g:i a", strtotime($holiday['Holiday']['created'])); ?></td>
        <td><?php 
		if(array_key_exists($holiday['Holiday']['created_by'],$userbyid)):
			$name = explode('@',$userbyid[$holiday['Holiday']['created_by']]['username']);
			$name = explode('.',$name[0]);
			echo implode(' ',$name);
		endif;
		 ?></td>
    </tr>
    <?php endforeach; ?>
    <?php unset($user); ?>
</table>

<?php echo $this->Paginator->numbers(array('first' => 'First page')); ?>